浏览量 4421
2019/01/02 15:14
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>methods_and_computed</title>
<style>
span {
background: red;
display: inline-block;
padding: 10px;
color: #fff;
margin: 10px 0;
}
.changeColor span {
background: green;
}
.changeLength span:after {
content: "length";
margin-left: 10px;
}
</style>
</head>
<body>
<div id="vue-app">
<h1> 动态 CSS Class </h1>
<h2> 示例 </h2>
<button v-on:click="changeColor=!changeColor">changeColor</button>
<button v-on:click="changeLength=!changeLength">changeLength</button>
<div v-bind:class="compClasses">
<span>Brownwang</span>
</div>
</div>
<script src="/static/js/vue.min.js"></script>
<script>
new Vue({
el: "#vue-app",
data: {
changeColor: false,
changeLength: false
},
methods: {},
computed: {
compClasses: function () {
return {
changeColor: this.changeColor,
changeLength: this.changeLength
}
}
}
});
</script>
</body>
</html>
上一篇 搜索 下一篇